{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 421,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from qiskit import QuantumProgram\n",
    "from math import pi\n",
    "import math\n",
    "import numpy as np\n",
    "import Qconfig"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 773,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[ 0.9486833  -0.31622777]\n",
      "['b_zero_ls_measureX', 'b_zero_ls_measureY', 'b_zero_ls_measureZ', 'b_plus_ls_measureX', 'b_plus_ls_measureY', 'b_plus_ls_measureZ', 'b_minus_ls_measureX', 'b_minus_ls_measureY', 'b_minus_ls_measureZ']\n",
      "pre-mapping properties: {'size': 29, 'depth': 24, 'width': 4, 'bits': 4, 'factors': 1, 'operations': {'u1': 2, 'u2': 3, 'cx': 14, 'u3': 6, 'measure': 4}}\n",
      "initial layout: None\n",
      "final layout: {('qr', 0): ('q', 1), ('qr', 1): ('q', 0), ('qr', 2): ('q', 2), ('qr', 3): ('q', 4)}\n",
      "post-mapping properties: {'size': 59, 'depth': 39, 'width': 5, 'bits': 4, 'factors': 2, 'operations': {'u1': 4, 'u2': 26, 'cx': 20, 'u3': 5, 'measure': 4}}\n",
      "pre-mapping properties: {'size': 30, 'depth': 25, 'width': 4, 'bits': 4, 'factors': 1, 'operations': {'u1': 3, 'u2': 3, 'cx': 14, 'u3': 6, 'measure': 4}}\n",
      "initial layout: None\n",
      "final layout: {('qr', 0): ('q', 1), ('qr', 1): ('q', 0), ('qr', 2): ('q', 2), ('qr', 3): ('q', 4)}\n",
      "post-mapping properties: {'size': 64, 'depth': 41, 'width': 5, 'bits': 4, 'factors': 2, 'operations': {'u1': 5, 'u2': 31, 'cx': 20, 'u3': 4, 'measure': 4}}\n",
      "pre-mapping properties: {'size': 28, 'depth': 23, 'width': 4, 'bits': 4, 'factors': 1, 'operations': {'u1': 2, 'u2': 2, 'cx': 14, 'u3': 6, 'measure': 4}}\n",
      "initial layout: None\n",
      "final layout: {('qr', 0): ('q', 1), ('qr', 1): ('q', 0), ('qr', 2): ('q', 2), ('qr', 3): ('q', 4)}\n",
      "post-mapping properties: {'size': 64, 'depth': 41, 'width': 5, 'bits': 4, 'factors': 2, 'operations': {'u1': 6, 'u2': 30, 'cx': 20, 'u3': 4, 'measure': 4}}\n",
      "pre-mapping properties: {'size': 30, 'depth': 25, 'width': 4, 'bits': 4, 'factors': 1, 'operations': {'u1': 2, 'u2': 4, 'cx': 14, 'u3': 6, 'measure': 4}}\n",
      "initial layout: None\n",
      "final layout: {('qr', 0): ('q', 1), ('qr', 1): ('q', 0), ('qr', 2): ('q', 2), ('qr', 3): ('q', 4)}\n",
      "post-mapping properties: {'size': 59, 'depth': 39, 'width': 5, 'bits': 4, 'factors': 2, 'operations': {'u1': 5, 'u2': 25, 'cx': 20, 'u3': 5, 'measure': 4}}\n",
      "pre-mapping properties: {'size': 31, 'depth': 26, 'width': 4, 'bits': 4, 'factors': 1, 'operations': {'u1': 3, 'u2': 4, 'cx': 14, 'u3': 6, 'measure': 4}}\n",
      "initial layout: None\n",
      "final layout: {('qr', 0): ('q', 1), ('qr', 1): ('q', 0), ('qr', 2): ('q', 2), ('qr', 3): ('q', 4)}\n",
      "post-mapping properties: {'size': 81, 'depth': 53, 'width': 5, 'bits': 4, 'factors': 2, 'operations': {'u1': 5, 'u2': 41, 'cx': 26, 'u3': 5, 'measure': 4}}\n",
      "pre-mapping properties: {'size': 29, 'depth': 24, 'width': 4, 'bits': 4, 'factors': 1, 'operations': {'u1': 2, 'u2': 3, 'cx': 14, 'u3': 6, 'measure': 4}}\n",
      "initial layout: None\n",
      "final layout: {('qr', 0): ('q', 1), ('qr', 1): ('q', 0), ('qr', 2): ('q', 2), ('qr', 3): ('q', 4)}\n",
      "post-mapping properties: {'size': 64, 'depth': 41, 'width': 5, 'bits': 4, 'factors': 2, 'operations': {'u1': 7, 'u2': 29, 'cx': 20, 'u3': 4, 'measure': 4}}\n",
      "pre-mapping properties: {'size': 31, 'depth': 26, 'width': 4, 'bits': 4, 'factors': 1, 'operations': {'u1': 2, 'u3': 7, 'u2': 4, 'cx': 14, 'measure': 4}}\n",
      "initial layout: None\n",
      "final layout: {('qr', 0): ('q', 1), ('qr', 1): ('q', 0), ('qr', 2): ('q', 2), ('qr', 3): ('q', 4)}\n",
      "post-mapping properties: {'size': 59, 'depth': 39, 'width': 5, 'bits': 4, 'factors': 2, 'operations': {'u1': 4, 'u2': 25, 'u3': 6, 'cx': 20, 'measure': 4}}\n",
      "pre-mapping properties: {'size': 32, 'depth': 27, 'width': 4, 'bits': 4, 'factors': 1, 'operations': {'u1': 3, 'u3': 7, 'u2': 4, 'cx': 14, 'measure': 4}}\n",
      "initial layout: None\n",
      "final layout: {('qr', 0): ('q', 1), ('qr', 1): ('q', 0), ('qr', 2): ('q', 2), ('qr', 3): ('q', 4)}\n",
      "post-mapping properties: {'size': 78, 'depth': 52, 'width': 5, 'bits': 4, 'factors': 2, 'operations': {'u1': 4, 'u2': 38, 'u3': 6, 'cx': 26, 'measure': 4}}\n",
      "pre-mapping properties: {'size': 30, 'depth': 25, 'width': 4, 'bits': 4, 'factors': 1, 'operations': {'u1': 2, 'u3': 7, 'u2': 3, 'cx': 14, 'measure': 4}}\n",
      "initial layout: None\n",
      "final layout: {('qr', 0): ('q', 1), ('qr', 1): ('q', 0), ('qr', 2): ('q', 2), ('qr', 3): ('q', 4)}\n",
      "post-mapping properties: {'size': 65, 'depth': 42, 'width': 5, 'bits': 4, 'factors': 2, 'operations': {'u1': 7, 'u2': 29, 'u3': 5, 'cx': 20, 'measure': 4}}\n",
      "running on backend: local_qasm_simulator\n",
      "None\n"
     ]
    }
   ],
   "source": [
    "# We choose A = (1.5 0.5;0.5 1.5)\n",
    "# For this eigenvectors are |-> and |+> with 1 and 2 as eigenvalues\n",
    "# The idea is to first write A as R^T \\Lambda R, where \\Lambda has the eigenvalues in the diagonal\n",
    "# R for this system is same as H, the Hadamard operator\n",
    "A = np.empty((2,2))\n",
    "A[0,0] = 1.5\n",
    "A[0,1] = 0.5\n",
    "A[1,0] = 0.5\n",
    "A[1,1] = 1.5\n",
    "\n",
    "# Eigenvalues of A are 1 and 2 with |-> and |+> being the corresponding eigen vectors\n",
    "\n",
    "Q_program = QuantumProgram()\n",
    "\n",
    "# We are solving a 2x2 system\n",
    "# one ancilla qubit; q[3]\n",
    "# two register qubits; q[1] and q[2]\n",
    "# one input (b vector) qubit; q[0]\n",
    "\n",
    "# Create 4 qubits\n",
    "qr = Q_program.create_quantum_register('qr', 4)\n",
    "cr = Q_program.create_classical_register('cr', 4)\n",
    "\n",
    "#Create circuit\n",
    "qc = Q_program.create_circuit('linear_solve', [qr], [cr])\n",
    "\n",
    "# Step 1: Operating R matrix on b (stored in q[0])\n",
    "qc.h(qr[0])\n",
    "qc.cx(qr[0], qr[1])\n",
    "qc.cx(qr[1], qr[2])\n",
    "qc.x(qr[1])\n",
    "qc.swap(qr[1], qr[2])\n",
    "\n",
    "# Step 2: Controlled rotation to get 1/lambda_1 and 1/lambda_2\n",
    "qc.cu3(pi, 0.0, 0.0, qr[1], qr[3]) #controlled u3\n",
    "qc.cu3(pi/3, 0.0, 0.0, qr[2], qr[3]) #controlled u3\n",
    "\n",
    "# # Step 3: disentanglement -- essentially applying R^T on \\Lambda*R*b\n",
    "# # Reverse of Step 1\n",
    "qc.swap(qr[1], qr[2])\n",
    "qc.x(qr[1])\n",
    "qc.cx(qr[1], qr[2])\n",
    "qc.cx(qr[0], qr[1])\n",
    "qc.h(qr[0])\n",
    "\n",
    "# Circuits for b values\n",
    "# We consider three b vectors (zero [1;0], minus [1/sqrt(2);-1/sqrt(2)] and plus [1/sqrt(2);1/sqrt(2)])\n",
    "b_zero = Q_program.create_circuit('b_zero', [qr], [cr])\n",
    "\n",
    "b_plus = Q_program.create_circuit('b_plus', [qr], [cr])\n",
    "b_plus.h(qr[0])\n",
    "\n",
    "b_minus = Q_program.create_circuit('b_minus', [qr], [cr])\n",
    "b_minus.x(qr[0])\n",
    "b_minus.h(qr[0])\n",
    "\n",
    "# quantum circuit to measure q in standard basis \n",
    "measureZ = Q_program.create_circuit('measureZ', [qr], [cr])\n",
    "for i in range(4):\n",
    "    measureZ.measure(qr[i], cr[i])\n",
    "\n",
    "# quantum circuit to measure q in superposition basis \n",
    "measureX = Q_program.create_circuit('measureX', [qr], [cr])\n",
    "measureX.h(qr[0])\n",
    "for i in range(4):\n",
    "    measureX.measure(qr[i], cr[i])\n",
    "\n",
    "# quantum circuit to measure q in superposition basis \n",
    "measureY = Q_program.create_circuit('measureY', [qr], [cr])\n",
    "measureY.sdg(qr[0])\n",
    "measureY.h(qr[0])\n",
    "for i in range(4):\n",
    "    measureY.measure(qr[i], cr[i])\n",
    "    \n",
    "#ibmqx4\n",
    "coupling_map = {1: [0], 2: [0, 1, 4], 3: [2, 4]}\n",
    "\n",
    "# execute the quantum circuit \n",
    "backend = 'local_qasm_simulator' # the device to run on\n",
    "shots = 1000\n",
    "\n",
    "# Print openqasm \n",
    "b_val_dict = {}\n",
    "b_val_dict['b_zero'] = b_zero\n",
    "b_val_dict['b_plus'] = b_plus\n",
    "b_val_dict['b_minus'] = b_minus\n",
    "\n",
    "measure_dict = {}\n",
    "measure_dict['measureX'] = measureX\n",
    "measure_dict['measureY'] = measureY\n",
    "measure_dict['measureZ'] = measureZ\n",
    "\n",
    "circuits = []\n",
    "for b_key in b_val_dict.keys():\n",
    "    for measure_key in measure_dict.keys(): \n",
    "        circuit = b_key + '_ls_' + measure_key\n",
    "        Q_program.add_circuit(circuit, b_val_dict[b_key]+qc+measure_dict[measure_key] )\n",
    "        circuits.append(circuit)\n",
    "\n",
    "print(circuits)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 812,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "pre-mapping properties: {'size': 29, 'depth': 24, 'width': 4, 'bits': 4, 'factors': 1, 'operations': {'u1': 2, 'u2': 3, 'cx': 14, 'u3': 6, 'measure': 4}}\n",
      "initial layout: None\n",
      "final layout: {('qr', 0): ('q', 1), ('qr', 1): ('q', 0), ('qr', 2): ('q', 2), ('qr', 3): ('q', 4)}\n",
      "post-mapping properties: {'size': 59, 'depth': 39, 'width': 5, 'bits': 4, 'factors': 2, 'operations': {'u1': 4, 'u2': 26, 'cx': 20, 'u3': 5, 'measure': 4}}\n",
      "pre-mapping properties: {'size': 30, 'depth': 25, 'width': 4, 'bits': 4, 'factors': 1, 'operations': {'u1': 3, 'u2': 3, 'cx': 14, 'u3': 6, 'measure': 4}}\n",
      "initial layout: None\n",
      "final layout: {('qr', 0): ('q', 1), ('qr', 1): ('q', 0), ('qr', 2): ('q', 2), ('qr', 3): ('q', 4)}\n",
      "post-mapping properties: {'size': 64, 'depth': 41, 'width': 5, 'bits': 4, 'factors': 2, 'operations': {'u1': 5, 'u2': 31, 'cx': 20, 'u3': 4, 'measure': 4}}\n",
      "pre-mapping properties: {'size': 28, 'depth': 23, 'width': 4, 'bits': 4, 'factors': 1, 'operations': {'u1': 2, 'u2': 2, 'cx': 14, 'u3': 6, 'measure': 4}}\n",
      "initial layout: None\n",
      "final layout: {('qr', 0): ('q', 1), ('qr', 1): ('q', 0), ('qr', 2): ('q', 2), ('qr', 3): ('q', 4)}\n",
      "post-mapping properties: {'size': 76, 'depth': 46, 'width': 5, 'bits': 4, 'factors': 2, 'operations': {'u1': 4, 'u2': 37, 'cx': 26, 'u3': 5, 'measure': 4}}\n",
      "pre-mapping properties: {'size': 30, 'depth': 25, 'width': 4, 'bits': 4, 'factors': 1, 'operations': {'u1': 2, 'u2': 4, 'cx': 14, 'u3': 6, 'measure': 4}}\n",
      "initial layout: None\n",
      "final layout: {('qr', 0): ('q', 1), ('qr', 1): ('q', 0), ('qr', 2): ('q', 2), ('qr', 3): ('q', 4)}\n",
      "post-mapping properties: {'size': 81, 'depth': 42, 'width': 5, 'bits': 4, 'factors': 2, 'operations': {'u1': 7, 'u2': 40, 'cx': 26, 'u3': 4, 'measure': 4}}\n",
      "pre-mapping properties: {'size': 31, 'depth': 26, 'width': 4, 'bits': 4, 'factors': 1, 'operations': {'u1': 3, 'u2': 4, 'cx': 14, 'u3': 6, 'measure': 4}}\n",
      "initial layout: None\n",
      "final layout: {('qr', 0): ('q', 1), ('qr', 1): ('q', 0), ('qr', 2): ('q', 2), ('qr', 3): ('q', 4)}\n",
      "post-mapping properties: {'size': 75, 'depth': 42, 'width': 5, 'bits': 4, 'factors': 2, 'operations': {'u1': 8, 'u2': 36, 'cx': 23, 'u3': 4, 'measure': 4}}\n",
      "pre-mapping properties: {'size': 29, 'depth': 24, 'width': 4, 'bits': 4, 'factors': 1, 'operations': {'u1': 2, 'u2': 3, 'cx': 14, 'u3': 6, 'measure': 4}}\n",
      "initial layout: None\n",
      "final layout: {('qr', 0): ('q', 1), ('qr', 1): ('q', 0), ('qr', 2): ('q', 2), ('qr', 3): ('q', 4)}\n",
      "post-mapping properties: {'size': 69, 'depth': 46, 'width': 5, 'bits': 4, 'factors': 2, 'operations': {'u1': 5, 'u2': 32, 'cx': 23, 'u3': 5, 'measure': 4}}\n",
      "pre-mapping properties: {'size': 31, 'depth': 26, 'width': 4, 'bits': 4, 'factors': 1, 'operations': {'u1': 2, 'u3': 7, 'u2': 4, 'cx': 14, 'measure': 4}}\n",
      "initial layout: None\n",
      "final layout: {('qr', 0): ('q', 1), ('qr', 1): ('q', 0), ('qr', 2): ('q', 2), ('qr', 3): ('q', 4)}\n",
      "post-mapping properties: {'size': 69, 'depth': 46, 'width': 5, 'bits': 4, 'factors': 2, 'operations': {'u1': 3, 'u2': 33, 'u3': 6, 'cx': 23, 'measure': 4}}\n",
      "pre-mapping properties: {'size': 32, 'depth': 27, 'width': 4, 'bits': 4, 'factors': 1, 'operations': {'u1': 3, 'u3': 7, 'u2': 4, 'cx': 14, 'measure': 4}}\n",
      "initial layout: None\n",
      "final layout: {('qr', 0): ('q', 1), ('qr', 1): ('q', 0), ('qr', 2): ('q', 2), ('qr', 3): ('q', 4)}\n",
      "post-mapping properties: {'size': 76, 'depth': 46, 'width': 5, 'bits': 4, 'factors': 2, 'operations': {'u1': 3, 'u2': 37, 'u3': 6, 'cx': 26, 'measure': 4}}\n",
      "pre-mapping properties: {'size': 30, 'depth': 25, 'width': 4, 'bits': 4, 'factors': 1, 'operations': {'u1': 2, 'u3': 7, 'u2': 3, 'cx': 14, 'measure': 4}}\n",
      "initial layout: None\n",
      "final layout: {('qr', 0): ('q', 1), ('qr', 1): ('q', 0), ('qr', 2): ('q', 2), ('qr', 3): ('q', 4)}\n",
      "post-mapping properties: {'size': 95, 'depth': 53, 'width': 5, 'bits': 4, 'factors': 2, 'operations': {'u1': 5, 'u2': 48, 'u3': 6, 'cx': 32, 'measure': 4}}\n",
      "running on backend: local_qasm_simulator\n",
      "OPENQASM 2.0;\n",
      "include \"qelib1.inc\";\n",
      "qreg q[5];\n",
      "creg cr[4];\n",
      "u1(0.0) q[4];\n",
      "u2(0.0,3.141592653589793) q[2];\n",
      "u2(0.0,3.141592653589793) q[1];\n",
      "cx q[1],q[0];\n",
      "u2(0.0,3.141592653589793) q[0];\n",
      "cx q[2],q[0];\n",
      "u3(-6.283185307179586,1.5707963267948966,1.5707963267948966) q[0];\n",
      "u1(6.283185307179586) q[2];\n",
      "cx q[2],q[0];\n",
      "u2(0.0,3.141592653589793) q[0];\n",
      "u2(0.0,3.141592653589793) q[2];\n",
      "cx q[2],q[0];\n",
      "u2(0.0,3.141592653589793) q[2];\n",
      "u2(0.0,3.141592653589793) q[0];\n",
      "cx q[2],q[0];\n",
      "u2(0.0,3.141592653589793) q[0];\n",
      "u2(0.0,3.141592653589793) q[2];\n",
      "cx q[2],q[0];\n",
      "u2(0.0,3.141592653589793) q[2];\n",
      "u2(0.0,3.141592653589793) q[0];\n",
      "cx q[2],q[0];\n",
      "u2(0.0,3.141592653589793) q[0];\n",
      "u2(0.0,3.141592653589793) q[2];\n",
      "cx q[2],q[0];\n",
      "cx q[2],q[4];\n",
      "u3(-1.5707963267948966,0.0,-0.0) q[4];\n",
      "cx q[2],q[4];\n",
      "u2(0.0,0.0) q[4];\n",
      "cx q[2],q[4];\n",
      "u2(0.0,3.141592653589793) q[2];\n",
      "u2(0.0,3.141592653589793) q[4];\n",
      "cx q[2],q[4];\n",
      "u2(0.0,3.141592653589793) q[4];\n",
      "u2(0.0,3.141592653589793) q[2];\n",
      "cx q[2],q[4];\n",
      "u2(0.0,3.141592653589793) q[2];\n",
      "u2(0.0,3.141592653589793) q[0];\n",
      "cx q[2],q[0];\n",
      "u1(6.283185307179586) q[0];\n",
      "u3(-0.5235987755982989,3.141592653589793,3.141592653589793) q[2];\n",
      "cx q[2],q[0];\n",
      "u2(0.0,3.141592653589793) q[0];\n",
      "u2(0.0,3.141592653589793) q[2];\n",
      "cx q[2],q[4];\n",
      "u2(0.0,3.141592653589793) q[2];\n",
      "u2(0.0,3.141592653589793) q[4];\n",
      "cx q[2],q[4];\n",
      "u2(0.0,3.141592653589793) q[4];\n",
      "u2(0.0,3.141592653589793) q[2];\n",
      "cx q[2],q[4];\n",
      "u3(0.523598775598299,0.0,0.0) q[4];\n",
      "measure q[4] -> cr[3];\n",
      "cx q[1],q[0];\n",
      "u2(0.0,3.141592653589793) q[1];\n",
      "u2(0.0,3.141592653589793) q[0];\n",
      "cx q[1],q[0];\n",
      "u2(0.0,3.141592653589793) q[0];\n",
      "u2(0.0,3.141592653589793) q[1];\n",
      "cx q[1],q[0];\n",
      "u2(0.0,3.141592653589793) q[0];\n",
      "cx q[2],q[1];\n",
      "u2(0.0,3.141592653589793) q[2];\n",
      "u2(0.0,3.141592653589793) q[1];\n",
      "cx q[2],q[1];\n",
      "u2(0.0,3.141592653589793) q[1];\n",
      "u2(0.0,3.141592653589793) q[2];\n",
      "cx q[2],q[1];\n",
      "u3(3.141592653589793,0.0,3.141592653589793) q[2];\n",
      "cx q[2],q[1];\n",
      "measure q[1] -> cr[2];\n",
      "u2(0.0,3.141592653589793) q[2];\n",
      "cx q[2],q[0];\n",
      "u1(6.283185307179586) q[0];\n",
      "measure q[0] -> cr[0];\n",
      "u2(0.0,3.141592653589793) q[2];\n",
      "measure q[2] -> cr[1];\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# print(Q_program.get_qasms(circuits))\n",
    "result = Q_program.execute(circuits, backend=backend, shots=shots, coupling_map=coupling_map, silent=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 817,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYgAAAETCAYAAAAs4pGmAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3X14VOWd//H3F1K0KFKigBienYgSi1QD4m+7tkizQW2H\naimNtkKLltLiutVLKd2taXXbgn3cutCfpT4QWUuM2gqWx19rvai7VYiKVmJtIqAkjZRCwMXaxITv\n748zSYdwQjJhHsLk87ouLuacc8+cr1zH+cw55z73be6OiIhIe30yXYCIiPRMCggREQmlgBARkVAK\nCBERCaWAEBGRUAoIEREJpYAQEZFQaQsIM5tuZq+aWY2ZLeqgzSwzqzKz7Wb2s3TVJiIiR7N0PChn\nZn2BPwJFQC2wFbjG3avi2uQDFcBl7t5gZkPc/c8pL05ERELlpGk/k4Ead98BYGblwAygKq7N54Fl\n7t4A0JVwOOOMM3z06NHJr1ZEJIs999xzf3H3wZ21S1dA5AG745ZrgYvbtTkHwMz+G+gLfMPdNxzr\nQ0ePHk1lZWUy6xQRyXpm9npX2qUrILoiB8gHPgwMBzab2fvd/UB8IzObB8wDGDlyZLprFBHpNdJ1\nk7oOGBG3PDy2Ll4tsMbd33X3nQT3LPLbf5C7L3f3QncvHDy40zMkERHppnQFxFYg38zGmFk/oARY\n067N4wRnD5jZGQSXnHakqT4REWknLQHh7s3AjcBG4BWgwt23m9mdZhaNNdsI7DOzKuA3wG3uvi8d\n9YmIyNHS0s01VQoLC103qUVEEmNmz7l7YWft9CS1iIiEUkCIiEgoBYSIi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c4e5F7dYP\nBf6V4BflND0omb2y/RhQN9fu2Q38N/B1M/uSmRWYWXzvhO3AeIVD1nsWONXMJsavdPc97v4vBMfB\ndRmpTNIlq48BjebaDbHeCl8HDgOXAucC9Wb2DsHscVegkVt7g20EXRrvMbOfA78CquI6KQwnuB4t\n2SurjwFdYkqQmZ1DMITGQIIzsLMJurHVEjwDUQD8GHjkRLzmKImJnTkuAKYQTDd7iOC4yAEmARe5\n+18zV6GkWjYfAwqIBJnZKwRTCb4FNBAM5T2CYOTO5box3TvFnqK/hGBa0fcRfEnc4+67MlmXpE82\nHgMKiASYWTGwzN0jseUcII9gOOcrCYLis+7+p8xVKakW+yL4MkGvlafd/dW4bSe5e2Pr3xkrUlKq\ntxwDugeRmFOAPWY2wt13x+Z5eB143cyeAR4gmCjogUwWKSn3VYJLiQ5caWavA88QfFHUmdmZBDOG\nfSmDNUpq9YpjQGcQCTAzAx4lmCHqFnff0W77j4G+7q45h7OUmfUF1hM8IPkqwdnjeQSXFZoJviQ+\nDvzF3a/OVJ2SOr3pGNAZRAJivZf+Ffg+8IKZvUQQGE8SjMEUBWZmsERJvX4Ez8DscPffAU/Hfi1+\ngGBi+nNFi0o+AAAAo0lEQVSBDxLcnJTs1GuOAZ1BdFNsQvoZwNXAMIKQ2ODu92e0MEmL1uETWgdp\ni1s/D1js7qdnsDxJg95wDOgMopvc/XngeYKH5d4L9Gs/YZBkr9axdVq/GOK+JEYA92SyNkmP3nAM\n6AxCJInM7AzgbXd/J9O1SGZk0zGggBARkVAai0lEREIpIEREJJQCQkREQikgREQklAJCRERCKSBE\nRCTU/wcOoQJd14ncXQAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x10ba2af28>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "OPENQASM 2.0;\n",
      "include \"qelib1.inc\";\n",
      "qreg q[5];\n",
      "creg cr[4];\n",
      "u1(0.0) q[4];\n",
      "u2(0.0,3.141592653589793) q[2];\n",
      "u2(0.0,3.141592653589793) q[1];\n",
      "cx q[1],q[0];\n",
      "u2(0.0,3.141592653589793) q[0];\n",
      "cx q[2],q[0];\n",
      "u3(-6.283185307179586,1.5707963267948966,1.5707963267948966) q[0];\n",
      "u1(6.283185307179586) q[2];\n",
      "cx q[2],q[0];\n",
      "u2(0.0,3.141592653589793) q[0];\n",
      "u2(0.0,3.141592653589793) q[2];\n",
      "cx q[2],q[0];\n",
      "u2(0.0,3.141592653589793) q[2];\n",
      "u2(0.0,3.141592653589793) q[0];\n",
      "cx q[2],q[0];\n",
      "u2(0.0,3.141592653589793) q[0];\n",
      "u2(0.0,3.141592653589793) q[2];\n",
      "cx q[2],q[0];\n",
      "u2(0.0,3.141592653589793) q[2];\n",
      "u2(0.0,3.141592653589793) q[0];\n",
      "cx q[2],q[0];\n",
      "u2(0.0,3.141592653589793) q[0];\n",
      "u2(0.0,3.141592653589793) q[2];\n",
      "cx q[2],q[0];\n",
      "cx q[2],q[4];\n",
      "u3(-1.5707963267948966,0.0,-0.0) q[4];\n",
      "cx q[2],q[4];\n",
      "u2(0.0,0.0) q[4];\n",
      "cx q[2],q[0];\n",
      "u2(0.0,3.141592653589793) q[2];\n",
      "u2(0.0,3.141592653589793) q[0];\n",
      "cx q[2],q[0];\n",
      "u2(0.0,3.141592653589793) q[0];\n",
      "u2(0.0,3.141592653589793) q[2];\n",
      "cx q[2],q[0];\n",
      "cx q[2],q[4];\n",
      "u3(-0.523598775598299,0.0,-0.0) q[4];\n",
      "cx q[2],q[4];\n",
      "u3(0.523598775598299,0.0,0.0) q[4];\n",
      "measure q[4] -> cr[3];\n",
      "u2(0.0,3.141592653589793) q[2];\n",
      "u2(0.0,3.141592653589793) q[0];\n",
      "cx q[2],q[0];\n",
      "u2(0.0,3.141592653589793) q[0];\n",
      "u2(0.0,3.141592653589793) q[2];\n",
      "cx q[2],q[0];\n",
      "u2(0.0,3.141592653589793) q[2];\n",
      "u2(0.0,3.141592653589793) q[0];\n",
      "cx q[2],q[0];\n",
      "u3(-6.283185307179586,1.5707963267948966,1.5707963267948966) q[0];\n",
      "u1(6.283185307179586) q[2];\n",
      "cx q[2],q[0];\n",
      "u2(0.0,3.141592653589793) q[0];\n",
      "u2(0.0,3.141592653589793) q[2];\n",
      "measure q[2] -> cr[2];\n",
      "cx q[1],q[0];\n",
      "measure q[0] -> cr[1];\n",
      "u1(6.283185307179586) q[1];\n",
      "measure q[1] -> cr[0];\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# Plotting\n",
    "# import state tomography functions\n",
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline\n",
    "from qiskit.tools.visualization import plot_histogram, plot_state\n",
    "plot_histogram(result.get_counts('b_zero_ls_measureX'))\n",
    "print(result.get_ran_qasm('b_zero_ls_measureX'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 819,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAY4AAAETCAYAAAAh/OHhAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3Xt8VfWZ7/HPV1LoWFsKglZBIJh4IV4hoLb2Yi1CdQzV\nokZPLVM7Qy86ju2xao8VO9YO2nvnSEfpaIudU1MrbYMjgq3UW6sDSL0Fi9yshGGQAlKrGAg+54+1\niDshkL3Izt5J+L5fr/3KWr+11t4Pv9r97LV+N0UEZmZm+dqv1AGYmVnP4sRhZmaZOHGYmVkmThxm\nZpaJE4eZmWXixGFmZpk4cZiZWSZOHGZmlokTh5mZZVJW6gC6wqBBg2LEiBGlDsPMrEd58skn/xwR\ngzs6r1cmjhEjRrB48eJSh2Fm1qNI+lM+5/lRlZmZZeLEYWZmmThxmJlZJk4cZmaWiROHmZll4sRh\nZmaZOHGYmVkmThxmZpaJE4eZmWXixGFmZpk4cZiZWSZOHGZmlokTh5mZZeLEYWZmmThxmJlZJkVL\nHJImSlom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IEYEZEVKT7ZcAQknlmziL5\nUvs7z9Daea7r4kq/uK4g6d3zWEQsyznWLyKadv4tWZC9RG+pazeO5+8dwHpJhwFERHNE/CkifgFc\nR7I+xIRSBtiLuK6L68skswyfBkyX9F1JF0gakn6RvQf4bmlD7DV6RV37jiNP6RKa95CsyvXFyFnv\nOj3+A6BPeO3lTnNdF4+Sta3vJxlguYzkru5okscmzcATJKOY/xwR55Yqzt6gN9W1e1XlKe3h83+A\nbwN/kPQMyZfbApJ5k2qAySUMsddwXRdVX5KxMqsi4nHgsfRX74nAaJKebKeSNNZa5/SauvYdx16Q\nNBqYBJwLHELyhTYvIu4oaWC9kOu6OHZOb7Fz0r2c8qnA9Ig4sITh9Sq9oa6dODop7VLXNyK2lDqW\n3s51XTw5s7Z+DdgvIq4tdUy9VU+saycOM9stSYOA1yJia6lj6e16Ul07cZiZWSbujmtmZpk4cZiZ\nWSZOHGZmlokTh5mZZeLEYWZmmThxmJlZJv8fgQFRfdmGjP4AAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x10bb75eb8>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "OPENQASM 2.0;\n",
      "include \"qelib1.inc\";\n",
      "qreg q[5];\n",
      "creg cr[4];\n",
      "u1(0.0) q[4];\n",
      "u2(0.0,3.141592653589793) q[2];\n",
      "u2(0.0,3.141592653589793) q[1];\n",
      "cx q[1],q[0];\n",
      "u2(0.0,3.141592653589793) q[0];\n",
      "cx q[2],q[0];\n",
      "u3(-6.283185307179586,1.5707963267948966,1.5707963267948966) q[0];\n",
      "u1(6.283185307179586) q[2];\n",
      "cx q[2],q[0];\n",
      "u2(0.0,3.141592653589793) q[0];\n",
      "u2(0.0,3.141592653589793) q[2];\n",
      "cx q[2],q[0];\n",
      "u2(0.0,3.141592653589793) q[2];\n",
      "u2(0.0,3.141592653589793) q[0];\n",
      "cx q[2],q[0];\n",
      "u1(6.283185307179586) q[0];\n",
      "u2(0.0,3.141592653589793) q[2];\n",
      "cx q[2],q[4];\n",
      "u2(0.0,3.141592653589793) q[2];\n",
      "u2(0.0,3.141592653589793) q[4];\n",
      "cx q[2],q[4];\n",
      "u2(0.0,3.141592653589793) q[4];\n",
      "u2(0.0,3.141592653589793) q[2];\n",
      "cx q[2],q[4];\n",
      "u2(0.0,3.141592653589793) q[2];\n",
      "cx q[2],q[0];\n",
      "u1(6.283185307179586) q[0];\n",
      "u2(0.0,6.283185307179586) q[2];\n",
      "cx q[2],q[0];\n",
      "u2(0.0,3.141592653589793) q[0];\n",
      "u2(3.141592653589793,3.141592653589793) q[2];\n",
      "u2(0.0,3.141592653589793) q[4];\n",
      "cx q[2],q[4];\n",
      "u1(6.283185307179586) q[4];\n",
      "u3(-0.5235987755982989,3.141592653589793,3.141592653589793) q[2];\n",
      "cx q[2],q[4];\n",
      "u2(0.0,3.141592653589793) q[4];\n",
      "u2(0.0,3.141592653589793) q[2];\n",
      "cx q[2],q[0];\n",
      "u2(0.0,3.141592653589793) q[2];\n",
      "u2(0.0,3.141592653589793) q[0];\n",
      "cx q[2],q[0];\n",
      "u2(0.0,3.141592653589793) q[0];\n",
      "u2(0.0,3.141592653589793) q[2];\n",
      "cx q[2],q[0];\n",
      "u3(0.523598775598299,0.0,0.0) q[0];\n",
      "measure q[0] -> cr[3];\n",
      "cx q[2],q[4];\n",
      "u2(0.0,3.141592653589793) q[2];\n",
      "u2(0.0,3.141592653589793) q[4];\n",
      "cx q[2],q[4];\n",
      "u2(0.0,3.141592653589793) q[4];\n",
      "u2(0.0,3.141592653589793) q[2];\n",
      "cx q[2],q[4];\n",
      "u3(3.141592653589793,0.0,3.141592653589793) q[2];\n",
      "cx q[2],q[4];\n",
      "measure q[4] -> cr[2];\n",
      "u2(0.0,3.141592653589793) q[2];\n",
      "u2(0.0,3.141592653589793) q[1];\n",
      "cx q[2],q[1];\n",
      "u2(0.0,7.853981633974483) q[1];\n",
      "measure q[1] -> cr[0];\n",
      "u2(0.0,3.141592653589793) q[2];\n",
      "measure q[2] -> cr[1];\n",
      "\n"
     ]
    }
   ],
   "source": [
    "plot_histogram(result.get_counts('b_zero_ls_measureY'))\n",
    "print(result.get_ran_qasm('b_zero_ls_measureY'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 816,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYgAAAETCAYAAAAs4pGmAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3X98VdWZ7/HPQyK0glIJP6QBhHgiEmpADYjtjBWRAZkx\nTFvA6C2lYgfpxVrbqxanI1amDjrT2s5cqJVWftRejQrVxBFBBalWqxBFqUAlEVASGQqKODgSCDz3\nj32Ih7BDziHJPsnx+3698uLstdc+53GB58lea+21zN0RERFpqEO6AxARkbZJCUJEREIpQYiISCgl\nCBERCaUEISIioZQgREQklBKEiIiEUoIQEZFQShAiIhIqO90BNEf37t29f//+6Q5DRKRdeeWVV3a7\ne4+m6rXrBNG/f38qKirSHYaISLtiZm8nU09dTCIiEkoJQkREQilBiIhIKCUIEREJpQQhIiKhlCBE\nRCSUEoSIiIRSghARkVBKECIiEkoJQkREQilBiIhIKCUIEREJpQQhIiKhlCBERCSUEoSIiIRSghAR\nkVCRJQgzG2tmb5pZlZnNbKTOJDPbaGYbzOyBqGITaW+WL1/OwIEDicVi3HnnncecX7RoET169GDo\n0KEMHTqUX//61/XnsrKy6suLi4vry6+55hqGDBlCYWEhEyZMYN++fQDU1tZyxRVXEIvFuOCCC9i2\nbVv9NXPmzCEWizFw4EBWrFiRdHzSTrh7q/8AWcBbQB7QEXgdKGhQJx9YB5wWP+7Z1Puef/75LvJp\nU1dX53l5ef7WW295bW2tFxYW+oYNG46qs3DhQp8xY0bo9Z07dw4t37t3b/3r733vez5nzhx3d583\nb55fe+217u7+4IMP+qRJk9zdfcOGDV5YWOj79+/3LVu2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DDwEXA2cAOM/uY\nYPe4ccBv0xhixlBbR+o1gqmWvzSz3wHPABsTJgL0Iegnl+Zr922tLqYQZnYWwbIOXQnuss4kmI5W\nTTAvfzDwC+CRttp32F6oraMXvzubQfBEeh3BFqNHVskdBpyvRRFbRntvayWIEGa2iWBLwA8JVhI9\njWAhs1pgvgZLW47aOn3iT6pfSLCt6OcIvrx+6e7b0hlXJmqvba0E0YCZjQHmuXssfpwN5BKspfK3\nBF9e39SKos2nto5O/AvqBoLZNH9w9zcTznVy99ojf6YtyAyRSW2tQepjdQZ2mllfAHevc/e33f13\nwK0E+xOMSWeAGURtHZ1bCFbEHQnMMbOfmdkVZpYb/8I6HfhZekPMGBnT1rqDaCC+/eISgp2evu8J\n+yHHz/8CyHLtz9tsautoWLD38ZMEDyG+SXCHNoigu6MOeIngqd7d7v7VdMWZCTKtrTWLqYH4jJp/\nBH4KrDOz9QRfYqsI1gUqBiakMcSMobaOTEeC50y2uPsfgT/Ef4s9FziPYNbYXxEMmkrzZFRb6w7i\nOMzsPGA88FWgN8EX13J3X5DWwDKQ2rr1HVnW4cjicQnl04A57p6TxvAySqa0tRJEkuLT1Tq6+950\nx5Lp1NbRSFhl9J8J9lX/YbpjylTtta2VIEQ+5cysO/CRu3+c7lgyXXtrayUIEREJpWmuIiISSglC\nRERCKUGIiEgoJQgREQmlBCEiIqGUIEREJNT/ByMIvrGE8TwsAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x10ba191d0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plot_histogram(result.get_counts('b_zero_ls_measureZ'))\n",
    "print(result.get_ran_qasm('b_zero_ls_measureZ'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 820,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Expectation values\n",
    "theoretical_expectation_values = {}\n",
    "# X, Y, Z\n",
    "theoretical_expectation_values['b_zero'] = {'X':-0.6, 'Y':0.0, 'Z':0.8}\n",
    "theoretical_expectation_values['b_plus'] = {'X':1.0, 'Y':0.0, 'Z':0.0}\n",
    "theoretical_expectation_values['b_minus'] = {'X':-1.0, 'Y':0.0, 'Z':0.0}\n",
    "\n",
    "def expectation_values(b_key):    \n",
    "    print('Expectation Values for b: ' + str(b_key))\n",
    "    print('==============================================================')\n",
    "    circuits = []\n",
    "    for measure_key in measure_dict.keys():\n",
    "        circuits.append(b_key + '_ls_' + measure_key)\n",
    "        \n",
    "    for circuit in circuits:\n",
    "        result.get_counts(circuit)\n",
    "        # Get results with 1 in the ancilla qubit q[3]\n",
    "        try:\n",
    "            x1 = result.get_counts(circuit)['1000']/shots\n",
    "        except KeyError:\n",
    "            x1 = 0\n",
    "        try:\n",
    "            x2 = result.get_counts(circuit)['1001']/shots\n",
    "        except KeyError:\n",
    "            x2 = 0\n",
    "\n",
    "        # Scale the probabilities to add up to 1\n",
    "        sum = x1 + x2\n",
    "        x1 = x1/sum\n",
    "        x2 = x2/sum\n",
    "        expectation_value = x1-x2\n",
    "\n",
    "        print('local simulator ' + circuit[-1] + ': ' + str(expectation_value) + ' | ' + \\\n",
    "              'theoretical ' + circuit[-1] + ': ' + str(theoretical_expectation_values[b_key][circuit[-1]]))\n",
    "        print('--------------------------------------------------------------')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 821,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Expectation Values for b: b_zero\n",
      "==============================================================\n",
      "local simulator X: -0.6044657097288677 | theoretical X: -0.6\n",
      "--------------------------------------------------------------\n",
      "local simulator Y: -0.027113237639553478 | theoretical Y: 0.0\n",
      "--------------------------------------------------------------\n",
      "local simulator Z: 0.8160919540229884 | theoretical Z: 0.8\n",
      "--------------------------------------------------------------\n",
      "Expectation Values for b: b_plus\n",
      "==============================================================\n",
      "local simulator X: 1.0 | theoretical X: 1.0\n",
      "--------------------------------------------------------------\n",
      "local simulator Y: -0.064 | theoretical Y: 0.0\n",
      "--------------------------------------------------------------\n",
      "local simulator Z: 0.023622047244094502 | theoretical Z: 0.0\n",
      "--------------------------------------------------------------\n",
      "Expectation Values for b: b_minus\n",
      "==============================================================\n",
      "local simulator X: -1.0 | theoretical X: -1.0\n",
      "--------------------------------------------------------------\n",
      "local simulator Y: 0.006000000000000005 | theoretical Y: 0.0\n",
      "--------------------------------------------------------------\n",
      "local simulator Z: -0.02200000000000002 | theoretical Z: 0.0\n",
      "--------------------------------------------------------------\n"
     ]
    }
   ],
   "source": [
    "for b_key in b_val_dict.keys():\n",
    "    expectation_values(b_key)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
